﻿using System;
using System.Text;
using System.ServiceModel;
using System.ComponentModel;
using Sinacor.Infra.UI.Common;
using System.Collections.Generic;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Corretagem.Communication.Bovespa.Titulo.Mercado;

namespace Sinacor.UI.Bovespa.Corretagem.Communication
{
    public class Mercado : BaseCommunication
    {
        #region Construtor

        public Mercado(SessionInformation sessionInformation)
            : base(sessionInformation)
        {
        }

        #endregion

        #region ConsultarMercados

        public ModelCollection<Model.Mercado> ConsultarMercados(Model.Parameter.FiltroMercado request)
        {
            IMercado servico = null;
            ModelCollection<Model.Mercado> retorno = null;
            try
            {
                servico = null;
                using (ServiceInstance<IMercado> service = new ServiceInstance<IMercado>())
                {
                    servico = service.TryGetInstance(this.Session);
                        
                    FiltroMercadoRequest dd = new FiltroMercadoRequest();

                    List<MercadoResponse> listmercadoresponse = servico.ConsultarMercados(new Translator.ModelToDataContract.Mercado().ToFiltroMercadoRequest(request));

                    retorno = new Translator.DataContractToModel.Mercado().ToMercado(listmercadoresponse);
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }
            return retorno;
        }

        #endregion

    }
}
